
cc.Class({
  extends: cc.Component,

  properties: { 
      baseScoreManager: {
        default: null,
        type: cc.Label
      },
  },

  onLoad: function () {
    this.baseScoreManager.string = "0";
    this.targetScore = 0;
    this.currentScore = 0;
    this.intervalScore = 0;
  },

  update: function (dt) {
    if(this.currentScore < this.targetScore){
      this.currentScore = this.currentScore + Math.ceil(this.intervalScore*dt);
      if(this.currentScore > this.targetScore){
        this.currentScore = this.targetScore;
      }
      this.baseScoreManager.string = this.currentScore;
    }
  },
  
  updateBaseScore: function ( targetScore ){
    this.targetScore = targetScore;
    if(this.currentScore < this.targetScore){
      this.intervalScore = this.targetScore - this.currentScore;
      this.baseScoreManager.string = ""+this.currentScore;      
    }
    else {
      this.intervalScore = 0;
      this.currentScore = this.targetScore;
      this.baseScoreManager.string = ""+this.currentScore;
    }
  }

});
